package com.exam.configuration;

import com.exam.common.Constants;
import com.exam.service.AppManagerService;
import com.exam.util.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class InitParams implements CommandLineRunner {

    @Autowired
    AppManagerService appManagerService;

    public void initParam() {
        List<Map<String, String>> userInfoList = appManagerService.getUserInfo();
        for(Map<String, String> param : userInfoList) {
            String imei = MapUtils.getStringValueByKey(param, "imei");
            Constants.userInfo.put(imei, param);
        }
    }

    @Override
    public void run(String... args) {
        initParam();
    }
}
